package com.playball.lottery.util;

import com.playball.lottery.R;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

/**
 * 
* @ClassName: LuckySelNameDialog 
* @Description: TODO(姓名 弹出来) 
* @author vanszhen 
* @date 2014年5月9日 上午10:49:06 
*
 */
public class LuckySelNameDialog {
	/** 上下文 */
	private Context context;
	/** LayoutInflater */
	private LayoutInflater inflater;
	private View viewSelLot;
	private Dialog dialog;

	
	private EditText edtName ;


	public LuckySelNameDialog(Context context) {
		super();
		this.context = context;
		inflater = LayoutInflater.from(context);
	}

	/** 初始化对话框 */
	public void initDialogSelName( ) {
		viewSelLot = inflater.inflate(R.layout.jdd_lucky_selname, null);
		initView();
		LinearLayout layout = (LinearLayout) viewSelLot
				.findViewById(R.id.jdd_lucky_sel_name);

		edtName =(EditText) viewSelLot.findViewById(R.id.lucky_name);

		dialog = new Dialog(context, R.style.FullHeightDialog);
		dialog.setCancelable(true);

		/*
		 * 对话框的大小按屏幕的百分比设置
		 */
		Window dialogWindow = dialog.getWindow();
		DisplayMetrics metrics = new DisplayMetrics();
		((Activity) context).getWindowManager().getDefaultDisplay()
				.getMetrics(metrics);
		int width = (int) ((metrics.widthPixels) * 0.8);
		// int height=metrics.heightPixels;
		WindowManager.LayoutParams layoutParams = dialog.getWindow()
				.getAttributes();
		layoutParams.width = width;
		dialogWindow.setAttributes(layoutParams);
		dialog.show();
		dialog.setContentView(layout, new LinearLayout.LayoutParams(width,
				LinearLayout.LayoutParams.WRAP_CONTENT));
		dialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失

		
	 
	}

	
	/**内部接口*/
	public interface OnClickListner{
		void getSelInterface(String date);
	}
	
	OnClickListner lisnter ;
	
	 
	
	public void setLisnter(OnClickListner onClickLisnter) {
		// TODO Auto-generated method stub
		this.lisnter = onClickLisnter;
	}

	public String getSel(){
		String data = edtName.getText().toString().trim();
		return data;
	}
	
	/**
	 * 销毁 进度条
	 */
	private void destoryDialog() {
		dialog.dismiss();
	}

	/** 按钮 */
	private void initView() {

		Button btnwheelSure = (Button) viewSelLot
				.findViewById(R.id.btnwheelsure);
		Button btnwheelCanle = (Button) viewSelLot
				.findViewById(R.id.btnwheelcance);

		//确定
		btnwheelSure.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if(lisnter != null){
					lisnter.getSelInterface(getSel());
					destoryDialog();
				}
			}
		});
		
		btnwheelCanle.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				destoryDialog();
			}
		});
		
	}

	

}
